package com.htthorizon.neo4j.repository;


import com.htthorizon.neo4j.entity.RelationShip2;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface RelationShip2Repository extends Neo4jRepository<RelationShip2, Long> {
    @Query("MATCH (a)-[c:R2]->(b)  RETURN a , c , b")
    List<RelationShip2> All();
    @Query("MATCH (d:Model)<-[r:R2]-(b:BD) WHERE id(b) = $id RETURN d ,r,b")
    List<RelationShip2> getById(@Param("id") Long id);
    @Query("MATCH (d:Model)-[r:R2]->(b:BD) WHERE d.name CONTAINS $name RETURN d,r,b")
    List<RelationShip2> getByName(@Param("name")String name);
    @Query("MATCH (d:Model)-[r:R2]->(b:BD) WHERE id(r) = $id RETURN d ,r,b")
    List<RelationShip2> getById2(@Param("id")long id);
    @Query("MATCH (n) WHERE ANY(key IN keys(n) WHERE n[key] CONTAINS $name) RETURN n")
    List<Object> search(@Param("name")String name);

    @Query("MATCH p=(a:BD)-[r:R2]->(b:Model) Where id(b)= $id  RETURN a,r,b")
    List<RelationShip2> findByBdId(@Param("id")Long id);
}
